<?php
class Organization
{
    public $domainID;
    public $subDomainID;
    public $orgID;
    public $searchText;
    public $yearStart;
    public $yearEnd;
    public $appID = "AppID=ef05e706-247f-44f7-9315-87ce9ae099ac";
    public $masUrl = "http://academic.research.microsoft.com/json.svc/search?";
    public $endIdx;
    public $startIdx;
    private $json;
    
    public function getOrganizations() {
        $query = $this->masUrl . $this->appID . "&ResultObjects=Organization";
        
        if (!is_null($this->domainID)) 
        {
            $query .= "&DomainID=" . $this->domainID;
        }
        
          if (!is_null($this->subDomainID)) 
        {
            $query .= "&SubDomainID=" . $this->subDomainID;
        }
        
          if (!is_null($this->orgID)) 
        {
            $query .= "&OrganizationID=" . $this->orgID;
        }
        
          if (!is_null($this->searchText)) 
        {
            $query .= "&FullTextQuery=" . $this->searchText;
        }
        
        if (!is_null($this->yearStart)) 
        {
            $query .= "&YearStart=" . $this->yearStart;
        }
          
        if (!is_null($this->yearEnd)) 
        {
            $query .= "&YearEnd=" . $this->yearEnd;
        }
        
          if (!is_null($this->startIdx)) 
        {
            $query .= "&StartIdx=" . $this->startIdx;
        }
        
          if (!is_null($this->endIdx)) 
        {
            $query .= "&EndIdx=" . $this->endIdx;
        }
        
        
        //$query .= "&StartIdx=1&EndIdx=100";
        
        $response = file_get_contents($query);
        
        $this->json = json_decode($response);
    }
    
    public function getIds() 
    {
        $results = array();
        
        foreach ($this->json->d->Organization->Result as $university) 
        {
                $id = $university->ID;
                $name = $university->Name;
         
                $results[$id] = $name;
        }
        
        return $results;
    }
   
}
?>